package com.example.aigc_education.ws.handler;

import com.example.aigc_education.integration.request.ChatMessageRequestV2;
import com.example.aigc_education.rpc.api.v2.ChatServiceProto;
import com.example.aigc_education.utils.JsonUtils;
import com.example.aigc_education.ws.response.SingleSelectMessage;

public class SingleSelectMessageHandler extends AbstractMessageHandler{

    @Override
    public ChatMessageRequestV2 handle(ChatServiceProto.ChatMessage chatMessage) {
        ChatServiceProto.SingleSelectContent singleSelect = chatMessage.getContents(0).getSingleSelect();
        String content = singleSelect.getContent();
        SingleSelectMessage message = new SingleSelectMessage();
        message.setTitle(singleSelect.getTitle());
        message.setOptions(singleSelect.getOptionsList());
        message.setContent(JsonUtils.fromJson(content, SingleSelectMessage.Plan.class));
        message.setAnswer(singleSelect.getAnswer());

        return ChatMessageRequestV2.builder()
                .userId(String.valueOf(chatMessage.getUserId()))
                .type(chatMessage.getContents(0).getType())
                .role(ChatMessageRequestV2.Role.AI)
                .content(message)
                .messageId(chatMessage.getMessageId())
                .convId(String.valueOf(chatMessage.getConvId()))
                .build();
    }

    @Override
    protected int getRole() {
        return ChatServiceProto.Role.AI_VALUE;
    }

    @Override
    protected String getType() {
        return "single_select";
    }
}
